package com.it.myd.service.main.module.aimsg;

import com.it.myd.bean.box.MsgBoard;
import com.it.myd.dao.main.module.aimsg.AiMsgDao;
import com.it.myd.dao.main.module.msgboard.MsgBoardDao;
import org.springframework.ai.chat.ChatClient;
import org.springframework.ai.chat.StreamingChatClient;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AiMsgServiceImpl implements AiMsgService {

    private final ChatClient chatClient;
    @Autowired
    private AiMsgDao aiMsgDao;

    @Autowired
    public AiMsgServiceImpl(ChatClient chatClient, StreamingChatClient streamingChatClient) {
        this.chatClient = chatClient;
    }

    @Override
    public String completion(String message) {
        Prompt prompt = new Prompt(new UserMessage(message));
        return chatClient.call(prompt).getResult().getOutput().getContent();
    }

    public void saveMsg(MsgBoard msgBoard){
        aiMsgDao.insertMsgBoard(msgBoard);
    }

}
